// createRouter: 创建一个全局的路由实例对象
// createWebHistory: 创建一个history路由模式 
// createWebHashHistory: 创建一个hash模式路由
// 常见的路由模式: history模式 (正常路径  /xx/xx)   hash模式(#/xx/xx)
import { createRouter, createWebHashHistory } from 'vue-router'

import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'


const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  // 路由规则数组
  routes: [
    { path: '/login', component: Login },
    {
      path: '/',
      component: Layout,
      children: [
        // 默认的二级路由
        { path: '', component: Home }, // /
        { path: 'category/:id', component: Category }, // /category
        { path: 'category/sub/:id', component: SubCategory }
      ]
    }
  ],
  // 路由滚动行为定制
  scrollBehavior() {
    return {
      top: 0
    }
  }
})

export default router
